﻿using System;
using System.Diagnostics;

namespace TSharp.Core.AppBox.Tests
{
    class Utils
    {
        public static void Measure(string name, Action func)
        {
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            func();
            stopwatch.Stop();
            Console.WriteLine("-------------------------");
            Console.WriteLine("      " + name);
            Console.WriteLine("      Time: " + stopwatch.ElapsedMilliseconds + " ms");
            Console.WriteLine("-------------------------");

        }

        public static bool IsPrime(long x)
        {
            if (x <= 2) return x == 2;
            if (x % 2 == 0) return false;

            long sqrtx = (long)Math.Ceiling(Math.Sqrt(x));
            for (long i = 3; i <= sqrtx; i++)
            {
                if (x % i == 0)
                {
                    Console.Write("{0} = {1} x {2} \r\n", x, i, x / i);
                    return false;
                }
            }
            Console.Write("{0} is prime \r\n", x);
            return true;
        }
    }
}